import { Injectable } from '@nestjs/common';
import { IndicatorService } from '@/modules/data/indicator/indicator.service';
import { RESPONSE_CODE } from "@/enums/code";
import { CallResourceIndexUrlDot } from './resourceIndex.dto'


@Injectable()
export class ResourceIndexService {

  constructor(private indicatorService: IndicatorService) { }

  /**
   * 获取指标列表
   * @method get
   * @param callResourceIndexUrlDot 
   * @returns
   */
  async callResourceIndexUrl(callResourceIndexUrlDot: CallResourceIndexUrlDot) {
    const { resourceIndexId, factoryId } = callResourceIndexUrlDot;
    const query = {};
    if (factoryId) {
      query["factoryId"] = factoryId;
    }
    const rows = await this.indicatorService.publicMethods('findAll', {});
    const data = rows.map((item) => {
      const { indicatorCode, indicatorName, sourceType, unit } = item.dataValues;
      return {
        id: null,
        displayName: indicatorName,
        sourceUniqueKey: indicatorCode,
        sourceUniqueKeyType: sourceType,
        tag: indicatorCode,
        unitName: unit,
      };
    });
    return {
      code: RESPONSE_CODE.SUCCESS,
      data,
      msg: null,
    }
  }

}
